﻿using UnityEngine;
using System.Collections;

public class ControladorPersonaje : MonoBehaviour {
	public float fuerzaSalto = 100f;
	public bool enSuelo = true;
	public Transform comprobadorSuelo;
	private float comprobadorRadio = 0.08f;
	public LayerMask mascaraSuelo;
	private bool dobleSalto = false;
	private Animator animator;
	// Use this for initialization
	void Awake(){
		animator = GetComponent<Animator> ();
	}
	void Start () {
	
	}

	void FixedUpdate(){
		enSuelo = Physics2D.OverlapCircle (comprobadorSuelo.position, comprobadorRadio, mascaraSuelo);
		//animator.SetBool ("isGrounded", enSuelo);
		if (enSuelo) {
			dobleSalto = false;
		}
	}
	// Update is called once per frame
	void Update () {
		if ((enSuelo || !dobleSalto) && Input.GetMouseButtonDown(0)) {
			rigidbody2D.velocity  = new Vector2(rigidbody2D.velocity.x,fuerzaSalto);
			//rigidbody2D.AddForce(new Vector2(0,fuerzaSalto));
			if(!dobleSalto && !enSuelo){
				dobleSalto = true;
			}
		}
	}
}
